package com.itheima.homew;

import java.util.Random;
import java.util.Scanner;

public class PrintRandom {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入随机数范围以生成随机数");
       int a =  sc.nextInt();
        getRandomOrder(a);

    }

    public static void getRandomOrder(int b) {
        int[] Order = new int[b];
        //需求：在一个数组中存入一个随机不重复的5个数，随机数1-5
        Random r = new Random();
        int a;
        for (int i = 0; i < Order.length; i++) {
            a = (r.nextInt(Order.length) + 1);
            //判断是否相同
            for (int j = 0; j < Order.length; j++) {
                if (a == Order[j]) {//如果这里的随机数和数组某个元素重复
                    a = (r.nextInt(Order.length) + 1);//重新随机
                    j = -1;//重头开始重新检索;
                }
            }
            Order[i] = a;
            System.out.println(Order[i]-1);//在打印时缩范围至0到(x-1);
        }

    }
}
